﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BOHVote.BLL;

namespace BOH.Interview
{
    public partial class singleapplyVote : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["ApplyID"] != null)
                {
                    LoadData(Request.QueryString["ApplyID"].ToString());
                }
            }
        }

        public void LoadData(string ApplyID)
        {
            DataSet dst = ApplyClass.getApplyByID(ApplyID);
            if (dst != null && dst.Tables.Count > 0 && dst.Tables[0].Rows.Count > 0)
            {
                labApplyName.Text = dst.Tables[0].Rows[0]["Apply_Name"].ToString();
                labJobRank.Text = dst.Tables[0].Rows[0]["JobRankName"].ToString();
                labSubject.Text = dst.Tables[0].Rows[0]["SubjectName"].ToString();
                labSpeciality.Text = dst.Tables[0].Rows[0]["Speciality"].ToString();
            }
        }

        protected void butSave_Click(object sender, EventArgs e)
        {
            if(Request.QueryString["ApplyID"]!=null&&Request.QueryString["EvaluationType"]!=null)
            {
                string ApplyID = Request.QueryString["ApplyID"].ToString();
                string EvaluationType = Request.QueryString["EvaluationType"].ToString().ToUpper();
                string TotalNumber = Request.QueryString["TotalNumber"].ToString();
                string ActualNumber = hiddenActualNumber.Value.Trim();
                string AgreeNumber = hiddenAgreeNu.Value.Trim();
                string DenyNumber = HiddendisapproveNu.Value.Trim();
                string AbstrainNumber = HiddenAbstainNu.Value.Trim();
                string resultID = InterviewClass.CheckResultApplyID(ApplyID, EvaluationType);
                if (string.IsNullOrEmpty(TotalNumber))
                    TotalNumber = "0";
                if (string.IsNullOrEmpty(AbstrainNumber))
                {
                    AbstrainNumber = (Convert.ToInt32(TotalNumber) - (Convert.ToInt32(AgreeNumber) + Convert.ToInt32(DenyNumber))).ToString();
                }

                if (!String.IsNullOrEmpty(resultID)&&resultID!="0")
                    InterviewClass.UpdateInterviewResult(resultID, string.Empty, TotalNumber, AgreeNumber, DenyNumber, AbstrainNumber, string.Empty, ActualNumber);
                else
                    InterviewClass.InsertInterviewResult(ApplyID, string.Empty, EvaluationType, TotalNumber, AgreeNumber, DenyNumber, AbstrainNumber, string.Empty, ActualNumber);
            }
        }
    }
}
